﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;

using Tdv.Wfrp.CharacterGenerator.Client.Commands;
using System.Windows.Controls;
using Tdv.Wfrp.CharacterGenerator.Client.ViewModels.Interfaces;
using Tdv.Wfrp.CharacterGenerator.Client.Services;
using Tdv.Wfrp.CharacterGenerator.Services.Interfaces.Navigation;

namespace Tdv.Wfrp.CharacterGenerator.Client.ViewModels.Implementations
{
    public class MainViewModel : ViewModelBase, IMainViewModel
    {
        private static MainViewModel _MainViewModelSingleton = new MainViewModel();
        private DelegateCommand exitCommand;
        private DelegateCommand<NavigationTarget> navigateCommand;

        #region Constructor

        public MainViewModel()
        {
            // Blank
        }

        #endregion

        private UserControl _DisplayedView;

        public UserControl DisplayedView
        {
            get { return _DisplayedView; }
            set
            {
                if (_DisplayedView != value)
                {
                    _DisplayedView = value;
                    OnPropertyChanged("DisplayedView");
                }
            }
        }

        public ICommand ExitCommand
        {
            get
            {
                if (exitCommand == null)
                {
                    exitCommand = new DelegateCommand(Exit);
                }
                return exitCommand;
            }
        }

        public ICommand NavigateCommand
        {
            get
            {
                if (navigateCommand == null)
                {
                    navigateCommand = new DelegateCommand<NavigationTarget>(Navigate);
                }

                return navigateCommand;
            }
        }

        private void Exit()
        {
            Application.Current.Shutdown();
        }

        private void Navigate(NavigationTarget navTarget)
        {
            ServiceProvider.GetService<INavigationService>().Navigate(navTarget);
        }
    }
}
